package cn.fansunion.concurrent.threadabc;

//有3个线程ABC。按照ABC来运行（A线程输出A，B线程输出B，C线程输出C，以此类推，循环输出）。
public class ThreadABCTest5 {

	public static void main(String[] args) {
		final int maxNum = 3;

		final Thread cThread = new Thread(new Runnable() {

			@Override
			public void run() {
				for (int index = 0; index < maxNum; index++) {
					try {
						wait();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println("C");
				}

			}

		});
		
		final Thread  bThread = new Thread(new Runnable() {

			@Override
			public void run() {
				for (int index = 0; index < maxNum; index++) {
					try {
						wait();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println("B");
					cThread.notify();
				}

			}

		});
		
		Thread aThread =new Thread(new Runnable() {

			@Override
			public void run() {
				for (int index = 0; index < maxNum; index++) {
					System.out.println("A");
					bThread.notify();
				}

			}

		});
		
		cThread.start();
		bThread.start();
		aThread.start();
	

	}

}
